package com.tim.app.ui.adapter.found;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.application.library.widget.recycle.BaseRecyclerAdapter;
import com.tim.app.R;
import com.tim.app.server.entry.Story;

import java.util.List;


/**
 * 每日一听的适配器
 */
public class HotEverydayHearAdapter extends BaseRecyclerAdapter<BaseRecyclerAdapter.BaseRecyclerViewHolder, Story> {

    static final String TAG = "StoryAdapter";

    private Context mContext;

    private int index = -1;

    public HotEverydayHearAdapter(Context mContext, List<Story> mDataList) {
        super(mDataList);
        this.mContext = mContext;
    }

    public int getIndex() {
        return index;
    }

    public void setIndex(int index) {
        this.index = index;
    }

    @Override
    public BaseRecyclerViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        BaseRecyclerViewHolder holder = null;
        holder = new ViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.cell_hot_every_day_hear, parent, false));
        return holder;
    }

    @Override
    public void onBindViewHolder(final BaseRecyclerViewHolder mHolder, int position, final Story data) {

        if (null == data)
            return;
        final ViewHolder holder = (ViewHolder) mHolder;
        if (!TextUtils.isEmpty(data.getTitle())) {
            holder.tvName.setText(data.getTitle().trim());
        } else {
            holder.tvName.setText("");
        }
        if (position == getIndex()) {
            holder.tvName.setSelected(true);
        } else {
            holder.tvName.setSelected(false);
        }
    }


    public class ViewHolder extends BaseRecyclerViewHolder {

        TextView tvName;

        public ViewHolder(View itemView) {
            super(itemView);
            tvName = (TextView) itemView.findViewById(R.id.tvName);
        }

    }

}
